//
//  RootViewController.m
//  解析音乐地址
//
//  Created by dllo on 15/12/10.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "MusicInfo.h"

@interface RootViewController ()

@property (nonatomic, retain) NSMutableArray *musicArr;

@end

@implementation RootViewController

- (void)dealloc
{
    [_musicArr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self getData];
    
//    NSString *song = [[self.musicArr objectAtIndex:0] singer_name];
//    
//    NSLog(@"%@", song);
    
}

- (void)getData
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString *str = @"http://iting.music.189.cn:9200/iting2/imusic/V2?resid=102191962&page=1&size=10&protocolCode=2.0&method=get_user_song_single_details&sid=240897694&networkType=wifi&serviceCode=100&sessionId=BF36F5454DBC9B92C20C48AEB373E17C&format=json&timestamp=20151210190756&sign=54d739a724206f183fac254eee599ef0&imsi=549599676310102&imei=7CBD8B23-4274-46A8-BDEF-A5F678020A09&company=cmwap&appChannelCode=10000000&appVerCode=2.008.001&parentPath=recommendMusicPlayList";
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
//        NSLog(@"%@", responseObject);
        self.musicArr = [NSMutableArray array];
        NSMutableDictionary *dic = (NSMutableDictionary *)responseObject;
        NSMutableDictionary *dataDic = [dic objectForKey:@"data"];
        NSMutableArray *arr = [dataDic objectForKey:@"songlist"];
        for (NSMutableDictionary *tempDic in arr) {
            MusicInfo *music = [[MusicInfo alloc] init];
//            music.singer_name = [tempDic objectForKey:@"singer_name"];
//            NSLog(@"%@", music.singer_name);
            [music setValuesForKeysWithDictionary:tempDic];
            [self.musicArr addObject:music];

            [music release];
        }
        NSString *song = [[[self.musicArr objectAtIndex:0] zlListenURL] objectForKey:@"url"];
        
        NSLog(@"%@", song);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    

    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
